<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        var name = '张三'
        var age = 18

        // 属性的简写：属性名和变量名相同时可以简写
        var user = {name, age}

        // 方法简写
        var student = {
            name,
            age,
            study(){
                console.log('学习')
            }
        }

        // 动态属性名
        // student.sex = '男'

        var _sex = ''
        Object.defineProperty(student, 'sex', {
            // value:'男',
            // writable:false, // 是否可写
            // configurable:true, // 是否可配置
            // enumerable:false, // 是否可枚举
            get: function(){ // 获取属性值时触发
                console.log('获取属性值时触发')
                return _sex
            },
            set:function(value){ // 设置属性值时触发
                console.log('有人修改了sex.........')
                _sex = value.toUpperCase()
            }
        })

        student.sex = 'male'
        // delete student.sex

        console.log(student.sex)

        
    </script>
</head>
<body>
    
</body>
</html>